<template>
  <a-card title="联系我们" style="width: 100%" >
    <a-form style="height: 50vh" :form="form" :label-col="{ span: 4 }" :wrapper-col="{ span: 18 }" @submit="handleSubmit">
      <a-form-item label="反馈类型">
        <a-radio-group v-decorator="['feedbackType',{ rules: [{ required: true, message: '请选择反馈类型' }] }]">
          <a-radio v-for="item in contectType || []" :value="item.id" :key="item.id">
            {{item.type}}
          </a-radio>
        </a-radio-group>
      </a-form-item>

      <a-form-item label="反馈内容">
        <a-textarea
            placeholder="请输入反馈内容，我们尽快将结果反馈给您邮箱!"
            :rows="4"
            v-decorator="['feedbackContent', { rules: [{ required: true, message: '请填写反馈内容!' }] }]"
        />
      </a-form-item>

      <a-form-item :wrapper-col="{ span: 12, offset: 4 }">
        <a-button type="primary" html-type="submit">
          提交反馈
        </a-button>
      </a-form-item>
    </a-form>
  </a-card>
</template>

<script>
import {addFeedback, getType} from "@/api/feedback";

export default {
  name: "contactus",
  data(){
    return {
      contectType:[],
      form: this.$form.createForm(this, { name: 'form' }),
    }
  },
  mounted() {
    // 加载反馈类型
    this.loadContactType();
  },
  methods:{
    async loadContactType(){
      const {code,data} = await getType();
      if (code === 200){
        this.contectType = data;
      }
    },
    // 提交反馈
    handleSubmit(e) {
      e.preventDefault();
      const _this = this;
      this.form.validateFields((err, values) => {
        if (!err) {
          addFeedback(values).then(res => {
            if (res.code === 200){
              _this.$message.success(res.msg);
              _this.form.resetFields();
            }else {
              _this.$message.error(res.msg);
            }
          })
        }
      });
    },
  }
}
</script>

<style scoped>

</style>
